home *** CD-ROM | disk | FTP | other *** search
/ Reverse Code Engineering RCE CD +sandman 2000 / ReverseCodeEngineeringRceCdsandman2000.iso / RCE / Ebooks / Thinking in C++ V2 / C24 / RTTIandMultipleInheritance.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2000-05-25  |  699 b   |  28 lines

  1. //: C24:RTTIandMultipleInheritance.cpp
  2. // From Thinking in C++, 2nd Edition
  3. // Available at http://www.BruceEckel.com
  4. // (c) Bruce Eckel 1999
  5. // Copyright notice in Copyright.txt
  6. #include <iostream>
  7. #include <typeinfo>
  8. using namespace std;
  9.  
  10. class BB {
  11. public:
  12.   virtual void f() {}
  13.   virtual ~BB() {}
  14. };
  15. class B1 : virtual public BB {};
  16. class B2 : virtual public BB {};
  17. class MI : public B1, public B2 {};
  18.  
  19. int main() {
  20.   BB* bbp = new MI; // Upcast
  21.   // Proper name detection:
  22.   cout << typeid(*bbp).name() << endl;
  23.   // Dynamic_cast works properly:
  24.   MI* mip = dynamic_cast<MI*>(bbp);
  25.   // Can't force old-style cast:
  26.   //! MI* mip2 = (MI*)bbp; // Compile error
  27. } ///:~
  28.